﻿using JinJun.EF.Permission.BLL;
using JinJun.EF.Permission.Model;
using JinJun.EF.Permission.Web.Attributes;
using JinJun.EF.Permission.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace JinJun.EF.Permission.Web.Controllers
{
    [PermissionAttribute]
    public class SystemLogsController : Controller
    {

        //创建业务层对象
        private SystemLogsService systemLogsService = new SystemLogsService();


        /// <summary>
        /// 操作日志分页查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <returns></returns>
        public JsonResult QueryPageList(int page, int limit, string username)
        {
            //创建分页类对象
            PageListResult<SystemLogs> pageListResult = new PageListResult<SystemLogs>();
            //赋值
            pageListResult.code = 0;
            pageListResult.msg = string.Empty;
            int count = 0;
            //创建以SystemLogs为类型的List对象
            List<SystemLogs> systemLogs = new List<SystemLogs>();
            //表达式
            Expression<Func<SystemLogs, bool>> whereLambda = a => a.Id != 0;
            if (!string.IsNullOrEmpty(username))
            {
                whereLambda = a => a.UserName.Contains(username);
            }
            Expression<Func<SystemLogs, int>> orderbyLambda = a => a.Id;
            //调用分页查询
            pageListResult.data = systemLogsService.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            pageListResult.count = count;
            return Json(pageListResult, JsonRequestBehavior.AllowGet);
        }
    }
}